package com.bawei.mdm2207alast.sign

import com.bawei.mdm2207alast.base.BaseViewModel
import com.bawei.mdm2207alast.base.IUiIntent
import com.bawei.mdm2207alast.model.RetrofitManager
import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody

/**
 * 作者：赵亮
 * 时间：2024/12/19 17:06
 * 功能：
 */
class SignViewModel : BaseViewModel() {
    override fun handIntent(it: IUiIntent) {
        when (it) {
            // 查询签到记录
            is SignIntent.SelSign -> httpRequest(RetrofitManager.apiService.selSign(it.map))

            // 签到
            is SignIntent.InsertSign -> httpRequest(
                RetrofitManager.apiService.insertSign(
                    RequestBody.Companion.create(
                        "application/json".toMediaType(),
                        Gson().toJson(it.map)
                    )
                )
            )
        }
    }
}